<%@ page language="java" pageEncoding="UTF-8" contentType="text/html;charset=UTF-8"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>创建射击成绩记录</title> 
<%@ include file="/common/include.jsp" %>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/fancybox/jquery.fancybox-1.3.4.pack.js"></script>
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/js/fancybox/jquery.fancybox-1.3.4.css" media="screen" />
<script>
$(document).ready(function() {
	var status = "${status}";
	if(status.length>0){
		if(status=="1")
		{
			alert("创建成功!");
		}else{
			alert("创建失败!");
		}
		window.location.href="${pageContext.request.contextPath}/ad/ad.list.do?actionType=page";
	}
	$("#select_terminal").fancybox({'width':'50%','height':'70%','type': 'iframe','autocenter':true
		,'onClosed':function(){
			if(window.selectTeminaleNode == null)
				return;
			$("#tmnm").val(window.selectTeminaleNode.name);
			$("#tmcd").val(window.selectTeminaleNode.id);
		}
	});
});

function add_test(){
		var tmcd = $("#tmcd").val();
		var location = $("#location").val();
// 		alert("tmcd:"+tmcd+"==location:"+location);
		$.ajax({
			type : 'POST',                           
			url : '${pageContext.request.contextPath }/ad_place/ad_place.testadd.do',
			async : false,
			data : 'tmcd=' + tmcd
					+ '&location='
					+ location,
			success : function(msg) {
// 				alert(msg);
				tmnm = msg;
			}
		})
		return tmnm;
}

function materialcreatesubmit() {
	var isValidatestate = true;
	var type_mask = '0';
	var cd_mask = '';
	var page = '1';
	var rows = '15';
	var r = /^[1-9]*[0-9][0-9]*$/; //正整数
	var t = /^([hH][tT]{2}[pP]:\/\/|[hH][tT]{2}[pP][sS]:\/\/)([\w-]+\.)+(\S)+$/i;
	var te = /^([\w-]+\.)+(\S)+$/i;
	var a = /select|insert|update|dalete|\'|\/\*|\.\.\/|union|into|load_file|outfile/;
	var name = $.trim($("#plnm").val()); //获取广告位名称
	var txt_len = $.trim(name).length;
	if (a.test(name)) {
		$("#nomaterialname").show();
		$("#nomaterialname").html('广告位名称格式有误');
		return false;
	}
	if (name == '') { //判断广告广告位名称不能为空,最大限制100个字
		$('#nomaterialname').show();
		$('#nomaterialname').html('广告位名称不能为空');
		isValidatestate = false;
	} else if (txt_len == 0) {
		$('#nomaterialname').show();
		$('#nomaterialname').html('广告位名称不能为空');
		isValidatestate = false;
	} else if (name.length > 100) {
			$('#nomaterialname').show();
			$('#nomaterialname').html('广告位名称超过最大限制100个字');
			return false;
	} else if(isExist("ad_place","plnm",name)>0){
		$('#nomaterialname').show();
		$('#nomaterialname').html('广告位名称已存在');
		isValidatestate = false;
	} else {
			$('#nomaterialname').hide();
	}
	name = $("#capacity").val();
// 	alert("capacity: " + r.test(name));
	if(name =='')
	{
		$("#tp_capacity").show();
		$("#tp_capacity").html('容量不能为空');
		return false;
	}else if (!r.test(name)|| name >9900 || name <1) {
		$("#tp_capacity").show();
		$("#tp_capacity").html('容量需为1到9900之间的正整数');
		return false;
	}
	$("#tp_capacity").hide();
	name = $("#top").val();
	if(name =='')
	{
		$("#tp_t").show();
		$("#tp_t").html('顶不能为空');
		return false;
	}else if (!r.test(name)|| name >9900) 
	{
		$("#tp_t").show();
		$("#tp_t").html('顶需为0到9900之间的整数');
		return false;
	}
	$("#tp_t").hide();
	name = $("#left").val();
	if(name =='')
	{
		$("#tp_l").show();
		$("#tp_l").html('左不能为空');
		return false;
	}else if (!r.test(name)|| name >9900) {
		$("#tp_l").show();
		$("#tp_l").html('左需为0到9900之间的整数');
		return false;
	}	
	$("#tp_l").hide();
	name = $("#width").val();
	if(name =='')
	{
		$("#tp_w").show();
		$("#tp_w").html('宽不能为空');
		return false;
	}else if (!r.test(name)|| name >9900) {
		$("#tp_w").show();
		$("#tp_w").html('宽需为0到9900之间的整数');
		return false;
	}	
	$("#tp_w").hide();
	name = $("#height").val();
	if(name =='')
	{
		$("#tp_h").show();
		$("#tp_h").html('高不能为空');
		return false;
	}else if (!r.test(name)|| name >9900) {
		$("#tp_h").show();
		$("#tp_h").html('高需为0到9900之间的整数');
		return false;
	}		
	$("#tp_h").hide();
	name = $("#tmnm").val();
	if(name =='')
	{
		$("#tmnm_h").show();
		$("#tmnm_h").html('所属终端不能为空');
		return false;
	}	
	$("#tmnm_h").hide();
	if(isValidatestate && add_test()!= "yes")
		document.getElementById("form").submit();
	else
		alert("同一个终端的同类型广告位只能存在一个！");
}

function comeback() {
	window.location="${pageContext.request.contextPath}/ad_place/ad_place.list.do?actionType=page";
}
</script>
</head>

<body>
<div class="wrapper">
     <jsp:include page="/common/header.jsp"><jsp:param value="1" name="nav"/></jsp:include>
	  		    <div class="content" style="">
		 	       <div class="col_l">
		         <div class="l_top"></div>
				 <div class="l_menu">
				      <jsp:include page="/common/l_ad_place.jsp"><jsp:param value="1" name="nav"/></jsp:include>
				 </div>
				 <div class="l_bottom"></div>
		   </div>
		   	   <div class="col_r" style="">
	   		         <div class="guide blue"><span class="left">当前位置：<a href="#">射击成绩管理</a> > 创建成绩记录</span></div>
				 <div class="mx_title">
				      <div class="cj_l"></div>
					  <div class="cj_c">
					      创建成绩记录
				      </div>
					  <div class="cj_r"></div>
				 </div>                
<form id="form" name="form" action="${pageContext.request.contextPath }/ad_place/ad_place.add.do?actionType=add" method="post">				 
				 <div class="cj_con" id="main" style="">
			          <table width="100%" border="0" cellspacing="0" cellpadding="0">
                         <tr style="" id='trmaterialname'>
                            <td width="14%" height="35" align="right">广告位名称：</td>
                            <td width="2%" align="center"><div class="star">*</div></td>
                            <td width="84%">
                            	<input type="text" id='plnm' name="plnm" size="35"  value=''class="input_cj left" />                 
                            	<div class="tips_error left" style="display:none;"  id='nomaterialname'></div>
                             </td>
                         </tr>
                         <tr style="">
                            <td height="35" align="right">类型：</td>
                            <td align="center"></td>
                            <td>
                            	 <select class="select_1" style="width: 120px" id="location" name="location">
									<c:forEach items="${locationList}" var="code">
												<option value="${code.cd}">
													${code.cdnm}
												</option>
											</c:forEach>
								</select> 
							</td>
                         </tr>
                         <tr>
								   <td height="35" align="right">容量：</td>
								   <td align="center"><div class="star">*</div></td>
								   <td colspan="2"><span class="left"><input type="text"  size="5" class="input_cj" id="capacity" name="capacity" /></span>
								   <div style="display:none;" class="tips_error left" id="tp_capacity"></div></td>
							</tr>
							<tr>
								   <td height="35" align="right">宽：</td>
								   <td align="center"><div class="star">*</div></td>
								   <td colspan="2"><span class="left"><input type="text"  size="5" class="input_cj" id="width" name="width" />PX</span>
								   <div style="display:none;" class="tips_error left" id="tp_w"></div></td>
							</tr>
							<tr>
								   <td height="35" align="right">高：</td>
								   <td align="center"><div class="star">*</div></td>
								   <td colspan="2"><span class="left"><input type="text"  size="5" class="input_cj" id="height" name="height" />PX</span>
								   <div style="display:none;" class="tips_error left" id="tp_h"></div></td>
							</tr>
							
							<tr>
								   <td height="35" align="right">左：</td>
								   <td align="center"><div class="star">*</div></td>
								   <td colspan="2"><span class="left"><input type="text"  size="5" class="input_cj" id="left" name="left" />PX</span>
								   <div style="display:none;" class="tips_error left" id="tp_l"></div></td>
							</tr>
							<tr>
								   <td height="35" align="right">顶：</td>
								   <td align="center"><div class="star">*</div></td>
								   <td colspan="2"><span class="left"><input type="text"  size="5" class="input_cj" id="top" name="top" />PX</span>
								   <div style="display:none;" class="tips_error left" id="tp_t"></div></td>
							</tr>
						     
							<tr>
								 <td height=35 align=right>所属终端：</td>
								<td align="center"><div class="star">*</div></td>
								<td class=blue>
									<span class="left">
									<input type="text" readonly="readonly" id="tmnm" name="tmnm"/>
									<a href="${pageContext.request.contextPath }/ad_place/terminal_tree.jsp" id="select_terminal" name="select_terminal">选择终端</a>
									<input type="hidden" id="tmcd" name="tmcd"/>
									</span>
									 <div style="display:none;" class="tips_error left" id="tmnm_h"></div>
								</td>
							</tr>
                      </table>
					   
					   <div style=" margin-left:120px; margin-top:10px;">
					  		<a href="javascript:void(0)" id='onsubmit'>
					  			<img onclick="materialcreatesubmit();" src="${pageContext.request.contextPath}/images/over.gif" />
					  		</a>
					    	<img onclick='comeback();'src='${pageContext.request.contextPath}/images/formcacle.gif' style="margin-left:15px;cursor:pointer"/>
					   </div>
		</div>
 </form> 
		</div>
		 
		   <div class="clear"></div>
		   
	  </div>

<div class=footer>CopyRight &copy;Research Institute of Computer Systems of SCUT. All Rights Reserved
	</div>
</div>
<script>
function showHelp(obj){
var help = document.getElementById("key"+obj).style.display;
document.getElementById("key"+obj).style.display="";

} 

function closeHelp(obj){
var help = document.getElementById("key"+obj).style.display;
document.getElementById("key"+obj).style.display="none";
}
	</script>
</body>
</html>